﻿using In66.Net.Elasticsearch;

namespace In66.Net.Share.Registrar
{
    public abstract partial class AbstractWebApiDependencyRegistrar
    {
        /// <summary>
        /// AddElasticsearch
        /// </summary>
        /// <param name="action"></param>
        public virtual void AddElasticsearch(Action<IServiceCollection> action = null)
        {
            action?.Invoke(Services);

            if (ElasticsearchSection is not null)
            {
                var elasticsearchConfig = ElasticsearchSection.Get<ElasticsearchConfig>();

                Services.AddElasticsearch(option =>
                {
                    option.Uri = elasticsearchConfig.Uri;
                    option.Pwd = elasticsearchConfig.Pwd;
                    option.User = elasticsearchConfig.User;
                });
            }
        }
    }
}
